#include "auditxls.h"

#include <iostream>
#include <QString>

#include <libxl/libxl.h>


int xlsOpenExcel(const char * const _filename, const int _mode) {

    std::cout << _filename << ": " << _mode << std::endl;
    return 0;
}

int xlsReadLine(char * const _line) {
    std::cout << _line << std::endl;
    return 0;
}

AUDITXLSSHARED_EXPORT int xlsReadLineTo100(const char * const _filename,
                                           char ** const _line,
                                           int *_row, int *_col) {
    using namespace libxl;
    // 初始化
    Book* book = xlCreateBook();
    if (!book)
        return 0 ;
    if (!book->load(_filename))
        return 0;
    Sheet* sheet = book->getSheet(0);
    if (!sheet)
        return 0;

    // 获得最大行列
    if (_row != Q_NULLPTR)
        *_row = sheet->lastRow();
    if (_col != Q_NULLPTR)
        *_col = sheet->lastCol();

//    _line = new char[];

    for (int r = 0; r < (*_row); ++r) {
        QString temp_line;
        for (int c = 0; c < (*_col); ++c) {
            temp_line += sheet->readStr(r,c);

            temp_line += ",";
        }
        _line[r] = temp_line.toUtf8().data();
    }


    return 0;
}

int xlsCloseExcel(int xlsHandle) {
    std::cout << xlsHandle << std::endl;
    return 0;
}



